import React from 'react'
import {connect} from 'react-redux'
import { Result, WhiteSpace ,List,Modal} from 'antd-mobile';
import browserCookie from 'browser-cookies'
import {Redirect} from 'react-router-dom'
import {logoutSubmit} from '../../redux/user.redux'
@connect(
    state=>state.user,
    {logoutSubmit}
)
class User extends React.Component{
    constructor(props){
        super(props)
        this.logout=this.logout.bind(this)
    }
    logout(){
        const alert=Modal.alert
        alert('注销', '你确认退出吗？', [
            { text: '取消', onPress: () => {} },
            { text: '确认', onPress: () => {
                browserCookie.erase('userid');
                this.props.logoutSubmit()
            } },
          ]);
        //删除cookie
        // browserCookie.erase('userid')

    }
    render(){
        const props=this.props;
        const Item=List.Item;
        const Brief=List.Item.Brief;
        // console.log(props.user)
        return props.user?(
            <div className='div'>
                
                <Result
                    img={<img src={require(`../img/${this.props.avatar}.png`)} alt='' style={{width:50}}/>}
                    title={this.props.user}
                    message={props.type=='boss'?props.company:null}
                />
                <List renderHeader={()=>'简介'}>
                    <Item multipleLine wrap>
                        {props.title}
                        
                        {props.desc.split('\n').map((v,index)=>
                            <Brief key={index}>{v}</Brief>
                        )}
                        {props.money?<Brief>薪资: {props.money}</Brief>:null}
                    </Item>
                </List>
                <WhiteSpace></WhiteSpace>
                <List>
                    <Item onClick={(this.logout)}>
                        退出登录
                    </Item>
                </List>
            </div>
           
        ):<Redirect to={props.redirectTo}/>
    }
}
export default User